home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / search / lsmtool-.6 / lsmtool- / lsmtool-0.6 / lsmextract.c < prev    next >
C/C++ Source or Header  |  1994-11-11  |  1KB  |  53 lines

  1. /*
  2.  * lsmextract.c -- extract LSM entries from input
  3.  *
  4.  * Usage: lsmextract [file ...]
  5.  * lsmextract reads the named files, or the standard input if none were
  6.  * named, searches for LSM entries, extracts them, and appends them to
  7.  * the two files "lsmextract.good" and "lsmextract.bad", depending on
  8.  * whether they seemed to fulfill all the syntactic and other requirements
  9.  * or not.  A report is printed to the standard output.  The report
  10.  * contains lines like:
  11.  *    title version
  12.  * where version and title come from the * version and title fields of
  13.  * the LSM entry.  Only good entries are included in the report.
  14.  *
  15.  * Lars Wirzenius
  16.  * "@(#)lsmtool:lsmextract.c,v 1.2 1994/11/11 19:16:53 wirzeniu Exp"
  17.  */
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <publib.h>
  24. #include "lsm.h"
  25.  
  26. int main(int argc, char **argv) {
  27.     static struct lsm_database db;
  28.     size_t i;
  29.     FILE *good, *bad;
  30.     struct lsm_entry *e;
  31.  
  32.     __set_liberror(__exit_on_error | __complain_on_error);
  33.     set_progname(argv[0], "lsmextract");
  34.  
  35.     if (lsm_read_database(stdin, &db) == -1)
  36.         errormsg(1, 0, "error in input");
  37.  
  38.     good = xfopen("lsmextract.good", "a");
  39.     bad = xfopen("lsmextract.bad", "a");
  40.  
  41.     for (i = 0; i < db.nentries; ++i) {
  42.         e = &db.entries[i];
  43.         if (lsm_check_entry(e, "") == -1)
  44.             lsm_write_one_entry(bad, e);
  45.         else {
  46.             lsm_write_one_entry(good, e);
  47.             printf("%s", e->fields[lsm_field_to_index("Title")]);
  48.         }
  49.     }
  50.  
  51.     return 0;
  52. }
  53.